/**
 * 
 */

var mappic=[null,null];

var mapdata = new Array();
var mapflgs = new Array();
var bgAudio=new Array();

var mapW =1080;
var mapH =960;

function DoMapEvent(x,y){
	if (onFight) return;
	eid =0;
	for (var i =0;i<mapflgs.length;i++){
		var tmp = mapflgs[i];
		if (parseInt(tmp[0]) == x && parseInt(tmp[1]) ==y ){
			eid =tmp[2];
			break;
		}
	}
	if (eid !=0) 
		OpenMapEvent(eid);
	
}

//战斗图
function CreateBrackground(pic){
	
	
	resetSound();
	sprites = new Array();
	sprites.push(AcceptSprite);
	
	PreLoadlst=new Array();
	actionlinks = new Array();
	onloading =1;
	
	mappic[0]= new Image();
	mappic[0].src = pic;
	mappic[1] = null; mappic[2]=null;
	onFight =1;
	
	onloading=0;
	createFight();
	
	
	
	PreLoadlst.push(mappic[0]);
	
	preload();
	AddExaction(new loadingSrc());
	
	for (i=0;i<bgAudio.length;i++){
		bgAudio[i].play();
	}
}

function Createmap(mapid){
	//
	resetSound();
	sprites = new Array();
	sprites.push(AcceptSprite);
	
	//PreLoadlst=new Array(); FIXed
	actionlinks = new Array();
	
	
	onloading =1;
	$.post('gmbg/getmap.php', {
	    m: mapid
	    },
		function(data){
	    	eval(data);
	    	onloading=0;
	    	preload();
	    	AddExaction(new loadingSrc());
	    	for (i=0;i<bgAudio.length;i++){
	    		bgAudio[i].play();
	    	}
	    	
	    }
	)
}



function initMap(m){
	//mapdata = new Array();
	mapflgs = new Array();
	
	var mlst = m.split('F');
	var ystr = mlst[0].split('|');
	
	for (var i=0;i<ystr.length;i++){
		var xstr=ystr[i];
		var xx = new Array();
		for (j=0;j<xstr.length;j++){
			xx[j] = xstr.substr(j,1);
		}
		
		mapdata[i] =xx;
	}
	
	ystr = mlst[1].split('|');
	
	for (var i=0;i<ystr.length;i++){
		xstr=ystr[i].split(',');
		if (xstr.length<3) return;
		xx = new Array();
		for (j=0;j<xstr.length;j++){
			xx[j] = xstr[j];
		}
		mapflgs[i] =xx;
	}
	
}

function resetSound(){
	for (i=0;i<bgAudio.length;i++){
		bgAudio[i].stop();
	}
	bgAudio=new Array();
}

//禁止混淆 Begin
//window['Createmap'] = Createmap; 
//window['CreateBrackground'] = CreateBrackground; 
//禁止混淆 END
